package com.whiteape.book.utils.web_dav;


import com.whiteape.book.core.manager.ReadSettingManager;
import com.whiteape.book.utils.StringUtils;
import com.whiteape.book.utils.web_dav.http.HttpAuth;

public class WebDavHelp {

    public static String getWebDavUrl() {
        String url = ReadSettingManager.getInstance().getWebDavUrl();
        assert url != null;
        if (!url.endsWith("/")) {
            url = url + "/";
        }
        return url;
    }

    public static boolean initWebDav() throws Exception{
        String account = ReadSettingManager.getInstance().getWebDavAccount();
        String password = ReadSettingManager.getInstance().getWebDavPassword();
        if (!StringUtils.isTrimEmpty(account) && !StringUtils.isTrimEmpty(password)) {
            HttpAuth.setAuth(account, password);
            return true;
        }
        throw new Exception("WebDav初始化失败,请检查您的WebDav设置，或者关闭WebDav备份功能");
//        return false;
    }

    private WebDavHelp() {

    }
}
